﻿using System;

namespace Validate.Net
{
    /// <summary>
    /// 邮箱格式匹配
    /// </summary>
    public class ValidateEmailAttribute : ValidateRegularAttribute
    {
        private static string regularStr = @"[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?";

        public ValidateEmailAttribute() : base(regularStr)
        { }
        public override bool Validate(object value, out string msg)
        {
            if (base.Validate(value, out msg))
                return true;
            else
            {
                msg = "邮箱格式校验失败";
                return false;
            }
        }
    }
}
